<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<% String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>优车处置信息维护</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <jsp:include page="../assParking/assParkCommon.jsp" flush="true" /><!-- 时间格式转换 -->
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div>
        <form id="dealSellInfo">
            <div class="fieldset1 tabel_col clearFix">
                <div class="Hide">
                    <input name="dealSellId" id="dealSellId" type="text" value="${dealSell.id}">
                </div>
                <%-- 收款方信息 --%>
                <c:if test="${type == 1}">
                <div class="fieldBox col_50">
                    <div class="label">收款银行<span class="requiredSymbol">*</span></div>
                    <div class="field">
                        <input name="payeeBankNm" id="payeeBankNm" type="text" class="ui-textbox" value="${dealSell.payeeBankNm }" validate="{required:true,stringMaxLength:100}">
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">收款账号<span class="requiredSymbol">*</span></div>
                    <div class="field">
                        <input name="payeeAccNo" id="payeeAccNo" type="text" class="ui-textbox" value="${dealSell.payeeAccNo }" validate="{required:true,stringMaxLength:50}">
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">收款方名称<span class="requiredSymbol">*</span></div>
                    <div class="field">
                        <input name="payeeAccNm" id="payeeAccNm" type="text" class="ui-textbox" value="${dealSell.payeeAccNm }" validate="{required:true,stringMaxLength:100}">
                    </div>
                </div>
                </c:if>

                <%-- 提车人信息 --%>
                <c:if test="${type == 2}">
                <div class="fieldBox col_50">
                    <div class="label">提车人姓名<span class="requiredSymbol">*</span></div>
                    <div class="field">
                        <input name="pickCarNm" id="pickCarNm" type="text" class="ui-textbox" value="${dealSell.pickCarNm }" validate="{required:true,stringMaxLength:50}">
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">提车人联系电话<span class="requiredSymbol">*</span></div>
                    <div class="field">
                        <input name="pickCarTel" id="pickCarTel" type="text" class="ui-textbox" value="${dealSell.pickCarTel }" validate="{required:true,stringMaxLength:20}">
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">提车人身份证号<span class="requiredSymbol">*</span></div>
                    <div class="field">
                        <input name="pickCarCd" id="pickCarCd" type="text" class="ui-textbox" value="${dealSell.pickCarCd }" validate="{required:true,stringMaxLength:32}">
                    </div>
                </div>
                </c:if>

                <%-- 编辑车辆评估价 --%>
                <c:if test="${type == 3}">
                    <div class="fieldBox col_50">
                        <div class="label">车辆评估价(元)<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input name="assessAmt" id="assessAmt" type="text" class="ui-textbox" value="<fmt:formatNumber value="${dealSell.assessAmt==null?null:dealSell.assessAmt/100}" pattern="0.##"/>" validate="{required:true,amount:true}">
                        </div>
                    </div>
                </c:if>

                <%-- 编辑处置信息 --%>
                <c:if test="${type == 4}">
                    <div class="fieldBox col_50">
                        <div class="label">拍卖状态<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input name="auctionStsCd" id="auctionStsCd" data-value="" placeholder="请选择" ltype="combobox" ligerui="width: 160" validate="{required:true}"/>
                        </div>
                    </div>
                    <div class="fieldBox col_50"></div>
                    <div id="dealSellEditDiv">
                    <div class="fieldBox col_50">
                        <div class="label">处置金额(元)<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input type="text" id="sellAmt" name="sellAmt" class="ui-textbox" value="<fmt:formatNumber value="${dealSell.sellAmt==null?null:dealSell.sellAmt/100}" pattern="0.##"/>" ligerui="width: 160" validate="{required:true,amount:true}"/>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">佣金(元)<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input type="text" id="commissionAmt" name="commissionAmt" class="ui-textbox" value="<fmt:formatNumber value="${dealSell.commissionAmt==null?null:dealSell.commissionAmt/100}" pattern="0.##"/>" ligerui="width: 160" validate="{required:true,amount:true}"/>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">成交时间<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input ligerui="width: 160" name="ycDealTmStr" id="ycDealTmStr" value="<fmt:formatDate value="${dealCar.ycDealTm}" pattern="yyyy-MM-dd"/>" type="text" class="ui-datepicker" validate="{required:true}"/>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">优车销售经理<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input name="sellManager" id="sellManager" placeholder="请选择" ligerui="width: 160" validate="{required:true}"/>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">处置接收人类型<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input name="buyerTypeCd" id="buyerTypeCd" data-value="" placeholder="请选择" ltype="combobox" ligerui="width: 160" validate="{required:true}"/>
                        </div>
                    </div>
                    <div class="fieldBox col_50"></div>
                    <!-- 个人信息 -->
                    <div class="fieldBox col_50 person Hide">
                        <div class="label">处置接收人姓名<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input type="text" id="buyerNm" name="buyerNm" class="ui-textbox" ligerui="width: 160" value="${dealSell.buyerNm}"/>
                        </div>
                    </div>
                    <div class="fieldBox col_50 person Hide">
                        <div class="label">联系方式<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input type="text" id="buyerTel" name="buyerTel" class="ui-textbox" ligerui="width: 160" value="${dealSell.buyerTel}"/>
                        </div>
                    </div>
                    <!-- 企业信息 -->
                    <div class="fieldBox col_50 company Hide">
                        <div class="label">处置接收企业名称<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input type="text" id="buyerCompanyNm" name="buyerCompanyNm" class="ui-textbox" ligerui="width: 160" value="${dealSell.buyerCompanyNm}" />
                        </div>
                    </div>
                    <div class="fieldBox col_50 company Hide">
                        <div class="label">处置接收企业联系人<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input type="text" id="buyerCompanyContact" name="buyerCompanyContact" class="ui-textbox" ligerui="width: 160" value="${dealSell.buyerCompanyContact}" />
                        </div>
                    </div>
                    <div class="fieldBox col_50 company Hide">
                        <div class="label">联系方式<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input type="text" id="buyerCompanyTel" name="buyerCompanyTel" class="ui-textbox" ligerui="width: 160" value="${dealSell.buyerCompanyTel}" />
                        </div>
                    </div>
                    </div>
                </c:if>

                <%-- 编辑到账状态 --%>
                <c:if test="${type == 5}">
                    <div class="fieldBox col_50">
                        <div class="label">到账状态<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input name="toAccStsCd" id="toAccStsCd" data-value="" placeholder="请选择" ltype="combobox" ligerui="width: 160" validate="{required:true}"/>
                        </div>
                    </div>
                </c:if>

                <%-- 编辑处置接收人证件号 or 组织机构代码证 --%>
                <c:if test="${type == 6}">
                    <div class="fieldBox col_50">
                        <div class="label">处置接收人类型<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input name="buyerTypeCd" id="buyerTypeCd" data-value="" placeholder="请选择" ltype="combobox" ligerui="width: 160" validate="{required:true}"/>
                        </div>
                    </div>
                    <div class="fieldBox col_50 person Hide">
                        <div class="label">处置接收人证件号<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input type="text" id="buyerCd" name="buyerCd" class="ui-textbox" ligerui="width: 160" value="${dealSell.buyerCd}" />
                        </div>
                    </div>
                    <div class="fieldBox col_50 company Hide">
                        <div class="label">组织机构代码证<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input type="text" id="buyerCompanyCode" name="buyerCompanyCode" class="ui-textbox" ligerui="width: 160" value="${dealSell.buyerCompanyCode}" />
                        </div>
                    </div>
                </c:if>

                <%-- 编辑付款信息 --%>
                <c:if test="${type == 7}">
                    <div class="fieldBox col_50">
                        <div class="label">实付金额(元)<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input type="text" id="bfsPayAmt" name="bfsPayAmt" class="ui-textbox" value="<fmt:formatNumber value="${dealSell.bfsPayAmt==null?null:dealSell.bfsPayAmt/100}" pattern="0.##"/>" ligerui="width: 160" validate="{required:true,amount:true}"/>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">实付时间<span class="requiredSymbol">*</span></div>
                        <div class="field">
                            <input name="bfsPayTmStr" id="bfsPayTmStr" value="<fmt:formatDate value="${dealSell.bfsPayTm}" pattern="yyyy-MM-dd"/>" type="text" class="ui-datepicker" validate="{required:true}" ligerui="width: 160" />
                        </div>
                    </div>
                </c:if>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    var type = '${type}';
    $(function () {
        $("#dealSellInfo").ligerForm({
            validate: true
        });

        if (type == '4') {
            initAuctionStsCdComboBox();
            initBuyerTypeComboBox(false);
            initSellManagerComboBox();
        }

        if (type == '5') {
            initAccStsCdComboBox();
        }

        if (type == '6') {
            initBuyerTypeComboBox(true);
        }

        // 点击确认事件
        frameElement.dialog.onOk = function () {
            var form = liger.get("dealSellInfo");
            if (!form.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }

            var formData = form.getData();
            formData.id = $("#dealSellId").val();
            formData.dealSellMgrId = $("#dealSellMgrId").val();
            var wait_dialog = null;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: formData,
                url: '<%=path%>/ass/ucardeal/modifyDealSell.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({
                            content: msg.info, SQ_showButtons: true, SQ_type: "success", onClose: function () {
                                var callback = frameElement.dialog.get("callBack");
                                if (callback != undefined) {
                                    callback(msg.data);
                                }
                                frameElement.dialog.close();
                            }
                        });
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        };

    });

    function initAccStsCdComboBox() {
        // 到账状态comboBox
        $("#toAccStsCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            width: 160,
            data: ${toAccStsList},
            value: '${dealSell.toAccStsCd}'
        });
    }

    function initAuctionStsCdComboBox() {
        // 拍卖状态comboBox
        $("#auctionStsCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            width: 160,
            data: ${auctionStsList},
            value: '${dealCar.auctionStsCd}',
            onChangeValue: function (newValue) {
                auctionChangeValue();
            }
        });
    }

    function initBuyerTypeComboBox(disabled) {
        // 处置接收人类型comboBox
        $("#buyerTypeCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            width: 160,
            data: ${buyerTypeList},
            value: '${dealSell.buyerTypeCd}',
            disabled: disabled,
            onChangeValue: function (newValue) {
                buyerTypeChangeValue();
            }
        });
    }

    function initSellManagerComboBox() {
        $("#sellManager").ligerComboBox({
            valueFieldID: 'dealSellMgrId',
            width: 100,
            onBeforeOpen: function(){
                $.ligerDialog.open({
                    title: '选择优车销售经理',
                    name: 'sellManagerSelector',
                    width: 500,
                    height: 370,
                    url: '<%=path%>/ass/ucardeal/toChooseSellManagerPage.do',
                    buttons: [
                         {text: '确定', onclick: onOk},
                         {text: '取消', cls: 'l-dialog-btn-no', onclick: onCancel}
                    ]
                });
                return false;
            }
        });
        var mgrId = '${dealSell.dealSellMgrId}';
        if (StringUtils.isNotEmpty(mgrId)) {
            $("#dealSellMgrId").val(mgrId);
            liger.get("sellManager").setText('${dealSell.dealSellMgrRlNm}[${dealSell.dealSellMgrUsrNm}]');
        }

        var onOk = function (item, Dialog) {
            var fn = Dialog.frame.f_select;
            var data = fn();
            if (!data) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            liger.get("sellManager").setText(data.dealSellMgrRlNm + '[' + data.dealSellMgrUsrNm + ']');
            $("#dealSellMgrId").val(data.dealSellMgrId);
            Dialog.close();
        };
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
    }

    function auctionChangeValue() {
        var value = liger.get("auctionStsCd").getValue();
        if (value == '2') {
            // 已上拍已成交
            $("#dealSellEditDiv").show();
            setValidate(true);
        } else {
            $("#dealSellEditDiv").hide();
            setValidate(false);
        }
    }

    function setValidate(validate) {
        var formSet = liger.get("dealSellInfo");
        if (validate) {
            formSet.setFieldValidate("sellAmt", {required: true, amount: true});
            formSet.setFieldValidate("commissionAmt", {required: true, amount: true});
            formSet.setFieldValidate("ycDealTmStr", {required: true});
            formSet.setFieldValidate("sellManager", {required: true});
            formSet.setFieldValidate("buyerTypeCd", {required: true});
        } else {
            formSet.setFieldValidate("sellAmt", {required: false});
            formSet.setFieldValidate("commissionAmt", {required: false});
            formSet.setFieldValidate("ycDealTmStr", {required: false});
            formSet.setFieldValidate("sellManager", {required: false});
            formSet.setFieldValidate("buyerTypeCd", {required: false});
        }
    }

    // 处置接受人类型onSelected事件
    function buyerTypeChangeValue() {
        var value = liger.get("buyerTypeCd").getValue();
        var formSet = liger.get("dealSellInfo");
        formSet.setData({
            buyerNm: '${dealSell.buyerNm}',
            buyerTel: '${dealSell.buyerTel}',
            buyerCompanyNm: '${dealSell.buyerCompanyNm}',
            buyerCompanyContact: '${dealSell.buyerCompanyContact}',
            buyerCompanyTel: '${dealSell.buyerCompanyTel}'
        });
        if (value == "1") {//企业
            $("#dealSellInfo").find(".company").each(function () {
                $(this).removeClass('Hide');
            });
            $("#dealSellInfo").find(".person").each(function () {
                $(this).addClass('Hide');
            });
            //取消个人《必选》验证规则
            formSet.setFieldValidate("buyerNm", {required: false});
            formSet.setFieldValidate("buyerCd", {required: false});
            formSet.setFieldValidate("buyerTel", {required: false});
            //设置企业《必选》验证规则
            formSet.setFieldValidate("buyerCompanyNm", {required: true, maxlength: 100});
            formSet.setFieldValidate("buyerCompanyContact", {required: true, maxlength: 50});
            formSet.setFieldValidate("buyerCompanyTel", {required: true, maxlength: 20});
            formSet.setFieldValidate("buyerCompanyCode", {required: true, maxlength: 100});
        } else if (value == "2") {//个人
            $("#dealSellInfo").find(".person").each(function () {
                $(this).removeClass('Hide');
            });
            $("#dealSellInfo").find(".company").each(function () {
                $(this).addClass('Hide');
            });
            //取消企业《必选》验证规则
            formSet.setFieldValidate("buyerCompanyNm", {required: false});
            formSet.setFieldValidate("buyerCompanyContact", {required: false});
            formSet.setFieldValidate("buyerCompanyTel", {required: false});
            formSet.setFieldValidate("buyerCompanyCode", {required: false});
            //设置个人《必选》验证规则
            formSet.setFieldValidate("buyerNm", {required: true, maxlength: 50});
            formSet.setFieldValidate("buyerCd", {required: true, maxlength: 32});
            formSet.setFieldValidate("buyerTel", {required: true, maxlength: 20});
        } else {
            $("#dealSellInfo").find(".company").each(function () {
                $(this).addClass('Hide');
            });
            $("#dealSellInfo").find(".person").each(function () {
                $(this).addClass('Hide');
            });
        }
    }

</script>
</body>
</html>